package io.renren.modules.sys.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.SongEntity;
import io.renren.modules.sys.service.SongService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author wangyi
 * @email 794651397@qq.com
 * @date 2018-02-24 10:46:32
 */
@RestController
@RequestMapping("/sys/song")
public class SongController {
	@Autowired
	private SongService songService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<SongEntity> songList = songService.queryList(query);
		int total = songService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(songList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Long id){
		SongEntity song = songService.queryObject(id);
		
		return R.ok().put("song", song);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody SongEntity song){
	    song.setCreateTime(new Date());
	    song.setReleaseTime(new Date());
		songService.save(song);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody SongEntity song){
	    song.setUpdateTime(new Date());
		songService.update(song);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Long[] ids){
		songService.deleteBatch(ids);

		return R.ok();
	}
	
}
